<?php
namespace hangpu8\hpcms\Utils;

use think\Response;

class Json
{

    /**
     * 返回成功数据
     *
     * @param array $array
     * @param string $msg
     * @param string $type
     * @return void
     */
    public static function successful(array $array = [],string $msg = 'success',$type = 'json') : Response
    {
        $data['msg']            = $msg;
        $data['code']           = 200;
        $data['date']           = date('Y-m-d H:i:s');
        $data['data']           = $array;
        return $type == 'json' ? json($data) : (array)$data;
    }

    /**
     * 返回错误数据
     *
     * @param string $msg
     * @param integer $code
     * @return json
     */
    public static function fail(string $msg,int $code = 404,$type = 'json') : Response
    {
        $data['msg']            = $msg;
        $data['code']           = $code;
        $data['date']           = date('Y-m-d H:i:s');
        return $type == 'json' ? json($data) : (array)$data;
    }
}